import java.util.Arrays;

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    @Override
    public int compareTo(Student o) {
        return this.name.compareTo(o.name);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class Test {
    public static void main4(String[] args) {
        Student stu1 = new Student("zhangsan",10);
        Student stu2 =new Student("lisi",20);

        AgeComparator ageComparator = new AgeComparator();
        int ret = ageComparator.compare(stu1,stu2);
        System.out.println(ret);

        NameComparator nameComparator = new NameComparator();
        ret = nameComparator.compare(stu1,stu2);
        System.out.println(ret);
    }
    public static void mysort(Comparable[] comparables) {
        int flag = 1;
        for (int i = 0; flag == 1 && i < comparables.length - 1; i++) {
            flag = 0;
            for (int j = 0; j < comparables.length - 1 - i; j++) {
                if(comparables[j].compareTo(comparables[j+1]) > 0){
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j+1];
                    comparables[j+1] = tmp;
                    flag = 1;
                }
            }
        }
    }

    public static void main3(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",10);
        students[1] = new Student("lisi",12);
        students[2] = new Student("wangwu",16);

        System.out.println("排序前：" + Arrays.toString(students));

        AgeComparator ageComparator = new AgeComparator();
        Arrays.sort(students,ageComparator);

        NameComparator nameComparator = new NameComparator();
        Arrays.sort(students,nameComparator);
    }
    public static void main2(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",10);
        students[1] = new Student("lisi",12);
        students[2] = new Student("wangwu",16);

        System.out.println("排序前：" + Arrays.toString(students));

        Arrays.sort(students);

        System.out.println("排序后：" + Arrays.toString(students));
    }
    public static void main1(String[] args) {
        Student stu1 = new Student("zhangsan",10);
        Student stu2 =new Student("lisi",20);

        System.out.println(stu1.compareTo(stu2));
    }
}